import { IToolTipItem } from "../../../../com/mui/manager/IToolTipItem";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ToolTipsManager } from "../../../../com/mui/manager/ToolTipsManager";
import { Cache } from "../../cache/Cache";
import { Language } from "../../../../extend/language/Language";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { LevelSealInfo } from "./info/LevelSealInfo";
import { BgLabelToolTip } from "../common/tooltip/BgLabelToolTip";
import { LayerManager } from "../../manager/LayerManager";
//class ExpBar
    
    export  class ExpBar /* flash.display.Sprite */ implements IToolTipItem
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._expBar = GlobalClass.getInstance("ExpBar") as Object /* flash.display.MovieClip */;
            this._expBar.x = 0;
            this._expBar.y = 1;
            this.addChild(this._expBar);
            this._label = ObjCreate.createTextField("", 250, -2, 220, 20, this, GlobalStyle.textFormat2);
            this._label.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ToolTipsManager.register(this);
            return;
        }

        public setValue(arg1: number, arg2: number): void
        {
            this._value = arg1;
            this._total = arg2;
            if (arg1 > arg2) 
            {
                arg1 = arg2;
            }
            var loc1=arg1 / arg2 * 100;
            this._expBar.gotoAndStop(loc1);
            var loc2;
            if ((loc2 = Math.floor(arg1 / arg2 * 100)) > 100) 
            {
                loc2 = 100;
            }
            this._label.text = loc2 + "%";
            this._isExpUpdate = true;
            return;
        }

        public get toolTipData()
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            this._levelSealInfo = Cache.instance.role.levelSealInfo;
            if (this._isExpUpdate) 
            {
                loc1 = Language.getString(30185) + Cache.instance.role.curWorldLevel;
                loc2 = Language.getString(90303) + Cache.instance.role.getWorldEx();
                loc3 = Language.getString(51000) + this._value + "/" + this._total;
                loc4 = "";
                if (this._levelSealInfo) 
                {
                    loc4 = loc4 + (Language.getStringByParam(90304, this._levelSealInfo.expAddPercent, this._levelSealInfo.playerName) + "<br>");
                }
                this._toolTipData = HTMLUtil.addColor("<font size=\'14\'>" + loc1 + "<br>" + loc2 + "<br>" + loc4 + loc3 + "</font>", "#ffffff");
                this._isExpUpdate = false;
            }
            return this._toolTipData;
        }

        public set toolTipData(arg1)
        {
            return;
        }

        public updateByLevelSealInfo(arg1: LevelSealInfo): void
        {
            if (arg1) 
            {
                flash.utils.setTimeout(this.showTip, 5000, true);
            }
            return;
        }

        /* internal  */showTip(arg1: Boolean): void
        {
            var loc1=null;
            if (arg1) 
            {
                if (!this._labelToolTip) 
                {
                    this._labelToolTip = new BgLabelToolTip();
                }
                this._labelToolTip.data = this.toolTipData;
                loc1 = localToGlobal(new Object /* flash.geom.Point */(295, -this._labelToolTip.height));
                this._labelToolTip.x = loc1.x;
                this._labelToolTip.y = loc1.y;
                if (!LayerManager.toolTipLayer.contains(this._labelToolTip)) 
                {
                    LayerManager.toolTipLayer.addChild(this._labelToolTip);
                }
                flash.utils.setTimeout(this.showTip, 4000, false);
            }
            else if (this._labelToolTip && LayerManager.toolTipLayer.contains(this._labelToolTip)) 
            {
                LayerManager.toolTipLayer.removeChild(this._labelToolTip);
            }
            return;
        }

        /* internal */ /* var */_expBar: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_label: Object /* flash.text.TextField */;

        /* internal */ /* var */_labelToolTip: BgLabelToolTip;

        /* internal */ /* var */_value: number;

        /* internal */ /* var */_total: number;

        /* internal */ /* var */_toolTipData;

        /* internal */ /* var */_isExpUpdate: Boolean=true;

        /* internal */ /* var */_levelSealInfo: LevelSealInfo;
    }
